package com.gemptc.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {
	private static final String DRIVER = "com.mysql.jdbc.Driver";
	private static final String URL = "jdbc:mysql://localhost:3306/hiking?useUnicode=true&characterEncoding=utf8";
	private static final String USERNAME = "root";
	//private static final String PASSWORD = "8865494";
	//private static final String PASSWORD = "123456";
	private static final String PASSWORD = "8023";
	// 连接	
	public static Connection getConnection() {
		Connection connection = null;
		try {
			// 加载驱动
			Class.forName(DRIVER);
			connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
			System.out.println("---------------"+connection);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}	
		return connection;
	}
	// 关闭连接
	public static void release(ResultSet resultSet,
			PreparedStatement preparedStatement, Connection connection) {
		try {
			if (resultSet != null) {
				resultSet.close();
			}
			if (preparedStatement != null) {
				preparedStatement.close();
			}
			if (connection != null) {
				connection.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
